﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.Base;

namespace ERP_RORZE_PRODUCT.Product.PartData
{
    public partial class ctrlPartMaterial : DevExpress.XtraEditors.XtraUserControl
    {
        ClsPartDataDAO clsPartdataDAO = new ClsPartDataDAO();
        DataTable dt;
        ClsPartDataTable obj = new ClsPartDataTable();
        public ctrlPartMaterial()
        {
            InitializeComponent();
        }
        void Re_load(object sender, EventArgs e)
        {
            dt = clsPartdataDAO.GetAllPartMaterial();
            dgvPartMaterial.DataSource = dt;
            gridView1.BestFitColumns();
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Frm_PartMaterialAdd frmAdd = new Frm_PartMaterialAdd();
            frmAdd.Re_Load += new EventHandler(Re_load);
            frmAdd.ShowDialog();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                Frm_PartMaterialEdit frmEdit = new Frm_PartMaterialEdit();
                frmEdit.Re_Load += new EventHandler(Re_load);
                frmEdit.Bafu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Bafu").ToString();
                frmEdit.BAnod = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "BAnod").ToString();
                frmEdit.Blast30 = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Blast30").ToString();
                frmEdit.Blast60 = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Blast60").ToString();
                frmEdit.Caciras = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Caciras").ToString();
                frmEdit.Cleanwave = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Cleanwave").ToString();
                frmEdit.Cut = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Cut").ToString();
                frmEdit.HairLine = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HairLine").ToString();
                frmEdit.HandFinish = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HandFinish").ToString();
                frmEdit.Helisert = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Helisert").ToString();
                frmEdit.InputDate = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "InputDate").ToString();
                frmEdit.Inside = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Inside").ToString();
                frmEdit.lenght = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "lenght").ToString();
                frmEdit.MaterialID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaterialID").ToString();
                frmEdit.MaterialType = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaterialType").ToString();
                frmEdit.Memo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Memo").ToString();
                frmEdit.Migaki = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Migaki").ToString();
                frmEdit.Note = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Note").ToString();
                frmEdit.Otherpro = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Otherpro").ToString();
                frmEdit.PalCoat = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "PalCoat").ToString();
                frmEdit.PartID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "PartID").ToString();
                frmEdit.Price = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Price").ToString();
                frmEdit.RawMachine = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "RawMachine").ToString();
                frmEdit.Seal = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Seal").ToString();
                frmEdit.SerialNo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SerialNo").ToString();
                frmEdit.shape = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "shape").ToString();
                frmEdit.Thickness = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Thickness").ToString();
                frmEdit.VacPac = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "VacPac").ToString();
                frmEdit.WAnod = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "WAnod").ToString();
                frmEdit.width = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "width").ToString();
                frmEdit.Workpiecesize = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Workpiecesize").ToString();
                frmEdit.ID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString();
                frmEdit.ShowDialog();
            }
            catch
            {
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            obj.ID = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString());
            clsPartdataDAO.DeleteMaterial(obj);
            Re_load(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Re_load(sender, e);
        }

        private void dgvPartMaterial_Load(object sender, EventArgs e)
        {
            Re_load(sender, e);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Re_load(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            btnAdd_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            btnDelete_Click(sender, e);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }

    }
}
